package com.pm.megapinhata.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Widget;
import com.pm.megapinhata.client.constants.NavigationContext;
import com.pm.megapinhata.client.factory.I18nFactory;
import com.pm.megapinhata.client.presenter.LayoutBasicPresenter;
import com.pm.megapinhata.client.presenter.MenuPresenter;
import com.pm.megapinhata.client.presenter.MenuPresenter.Display;
import com.pm.megapinhata.client.presenter.Presenter;
import com.pm.megapinhata.client.view.MenuView;
import com.pm.megapinhata.client.view.middle.InicialView;
import com.pm.megapinhata.client.view.models.impl.LayoutBasicView;

public class AppController implements Presenter, ValueChangeHandler<String> {
	
	public static Messages messages;
	private Widget widget;
	private LayoutBasicView layoutBasicView;
	
	public AppController() {
		messages = I18nFactory.getComponentesDominioPadrao();
		bind();
	}
	
	public void onValueChange(ValueChangeEvent<String> event) {
		String token = event.getValue();
		
		if (NavigationContext.HOME.getName().equals(token)) {
			layoutBasicView = new LayoutBasicView(new InicialView(),new MenuView());
			addPresenter(new Presenter[]{new LayoutBasicPresenter(layoutBasicView, this), new MenuPresenter((Display) layoutBasicView.getMenuLayout())});
		}/* else if (NavigationContext.PURCHASE_ORDER_REPORT.getName().equals(token)) {
			layoutBasicView.alteraConteudoCentral(new PurchaseOrderReportView(), NavigationContext.PURCHASE_ORDER_REPORT);
			addPresenter(new PurchaseOrderReportPresenter(layoutBasicView.getMiddleLayout().getLayoutMiddleView(), (PurchaseOrderReportView)layoutBasicView.getMiddleLayout()));
		}*/
		
	}
	
	public void go(){
		History.newItem(NavigationContext.HOME.getName());
	}
	
	public void bind() {
		History.addValueChangeHandler(this);
	}
	
	public Widget getWidget(){
		return widget;
	}
	
	public void bindPresenter(Presenter presenter){
		presenter.bind();
	}
	
	public void addPresenter(Presenter[] presenters){
		for(Presenter pres : presenters){
			pres.bind();
		}
	}
	
}
